package com.maikang.exammall.util;

import java.util.Random;
import java.util.UUID;

public class IDUtil {
    private static final String ORDER = "D";
    private static final String REFUND = "R";
    private static final String WITHDRAW = "W";

    public static String CreateUuid() {
        return UUID.randomUUID().toString();
    }

    /**
     *
     * @param type order type
     * @return 16 digits order number
     */
    private static String getOrderId(String type) {
        int machineId = 1;//最大支持1-9个集群机器部署
        int hashCodeV = UUID.randomUUID().toString().hashCode();
        if (hashCodeV < 0) {//有可能是负数
            hashCodeV = -hashCodeV;
        }

//         0 代表前面补充0     
//         4 代表长度为4     
//         d 代表参数为正数型
        return type + machineId + String.format("%014d", hashCodeV);
    }

    public static String create6RandomDigit() {
        Random random = new Random();
        String result="";
        for (int i=0;i<6;i++)
        {
            result+=random.nextInt(10);
        }
        return result;
    }

    public static String createOrderOutTradeNo() {
        return getOrderId(ORDER);
    }

    public static String createOutRefundNo() {
        return getOrderId(REFUND);
    }

    public static String createSaleWithdrawOutTradeNo() {
        return getOrderId(WITHDRAW);
    }


}
